package it.crosato.stage.shared.objects;

import java.util.Vector;

public class Pathway {

	private String id;
	private String name;
	private String description;
	private String url;
	private Vector<String> compounds = new Vector<String>();
	private Vector<Reaction> reactions = new Vector<Reaction>();
	private Vector<String> enzymes = new Vector<String>();
	
	public Pathway() {
		
	}
	
	public Pathway(String id, String name, String description, String url,
			Vector<Reaction> reactions, Vector<String> enzymes) {
		
		this.id = id;
		this.name = name;
		this.description = description;
		this.url = url;
		this.reactions = reactions;
		this.enzymes = enzymes;
		// compounds
		for (int i = 0; i < reactions.size(); i++) {
			Vector<ReactionElement> substrates = reactions.get(i).getSubstrates();
			Vector<ReactionElement> products = reactions.get(i).getProducts();
			for (int j = 0; j < substrates.size(); j++) {
				if ( ! compounds.contains(substrates.get(j).getElementCode())) {
					compounds.add(substrates.get(j).getElementCode());
				}
			}
			for (int j = 0; j < products.size(); j++) {
				if ( ! compounds.contains(products.get(j).getElementCode())) {
					compounds.add(products.get(j).getElementCode());
				}
			}
		}
	}
	
	/**
	 * Ritorna l'i-esima reazione chimica della via metabolica 
	 * @param i indice della reazione
	 * @return la reazioni i-esima o il valore nullo se l'indice non è corretto
	 */
	public Reaction getReaction(int i) {
		if (i < 0 || i >= reactions.size()) {
			return null;
		}
		return reactions.get(i);
	}
	
	/**
	 * Ritorna la reazione chimica con il codice dato in ingresso
	 * @param id codice della reazione
	 * @return la reazione con il codice in ingresso o il valore nullo se essa
	 * non è presente
	 */
	public Reaction getReaction(String id) {
		for (int i = 0; i < reactions.size(); i++) {
			if (reactions.get(i).getId().equals(id)) {
				return reactions.get(i);
			}
		}
		return null;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUrl() {
		return url;
	}
	
	public Vector<String> getCompounds() {
		return compounds;
	}
	public void setCompounds(Vector<String> compounds) {
		this.compounds = compounds;
	}
	
	public Vector<Reaction> getReactions() {
		return reactions;
	}
	public void setReactions(Vector<Reaction> reactions) {
		this.reactions = reactions;
		// compounds
		for (int i = 0; i < reactions.size(); i++) {
			Vector<ReactionElement> substrates = reactions.get(i).getSubstrates();
			Vector<ReactionElement> products = reactions.get(i).getProducts();
			for (int j = 0; j < substrates.size(); j++) {
				if ( ! compounds.contains(substrates.get(j).getElementCode())) {
					compounds.add(substrates.get(j).getElementCode());
				}
			}
			for (int j = 0; j < products.size(); j++) {
				if ( ! compounds.contains(products.get(j).getElementCode())) {
					compounds.add(products.get(j).getElementCode());
				}
			}
		}
	}
	
	public Vector<String> getEnzymes() {
		return enzymes;
	}
	public void setEnzymes(Vector<String> enzymes) {
		this.enzymes = enzymes;
	}
}